package models.inventory;

import models.core.BaseAttrSpec;
import models.core.CompositeAttrSpec;
import models.core.GipxyModel;
import play.data.validation.Constraints;

import javax.persistence.*;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: hungdq
 * Date: 4/30/12
 * Time: 4:21 PM
 * To change this template use File | Settings | File Templates.
 */
@Entity
public class ResourceSpec extends GipxyModel{
    @Constraints.Required
    public String name;
    public String description;
    public boolean duplicatable = false;


    @ManyToMany(cascade = CascadeType.ALL)
    public List<BaseAttrSpec> baseAttrSpecs;

    @ManyToMany(cascade = CascadeType.ALL)
    public List<CompositeAttrSpec> compositeAttrSpecs;

    public String getDisplayValue() {
        return description;
    }

    public static Finder<Long,ResourceSpec> find = new Finder<Long,ResourceSpec>(Long.class, ResourceSpec.class);


    public static Map<String,String> getValueSpace() {
        LinkedHashMap<String,String> options = new LinkedHashMap<String,String>();
        for(ResourceSpec c: ResourceSpec.find.orderBy("name").findList()) {
            options.put(c.id.toString(), c.getDisplayValue());
        }
        return options;
    }





            

}
